
//
//  InvitationViewController.m
//  LuxuryGoods
//
//  Created by DCQ on 2018/5/25.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "InvitationViewController.h"
#import "InvitationHeaderCell.h"
#import "InvitationContentCell.h"

NSString * const InvitationContentCellIdentifier = @"InvitationContentCellIdentifier";
NSString * const InvitationHeaderCellIdentifier = @"InvitationHeaderCellIdentifier";
@interface InvitationViewController ()

@end

@implementation InvitationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavigationItemTitle:@"分享APP"];
    self.view.backgroundColor = UIColorFromRGB(0xE25942);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)registerCell{
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([InvitationHeaderCell class]) bundle:nil] forCellReuseIdentifier:InvitationHeaderCellIdentifier];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([InvitationContentCell class]) bundle:nil] forCellReuseIdentifier:InvitationContentCellIdentifier];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    NSInteger sections = 1;
    
    return sections;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSInteger rows = 2;
    
    return rows;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat height =  0;
    if (indexPath.row == 0) {
        height = 350;
    }else{
        height = [self heightForString:[self getContentText] andWidth:self.view.frame.size.width -16*2]+4*2;
    }
    return height;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = nil;
    if (indexPath.row == 0) {
        InvitationHeaderCell * tempCell = [tableView dequeueReusableCellWithIdentifier:InvitationHeaderCellIdentifier];
        tempCell.btnBlock = ^{
            [self gotoInvitation];
        };
        cell = tempCell;
    }else if (indexPath.row == 1){
        InvitationContentCell * tempCell = [tableView dequeueReusableCellWithIdentifier:InvitationContentCellIdentifier];
        [tempCell setupContent:[self getContentText]];
        cell = tempCell;
        
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (NSString *)getContentText{
    NSString *content =  @"规则\n1,规则规则规则规则规则规则规则规则规则规则规则规则规则规则\n2,规则规则规则规则规则规则规则规则规则\n3.";
    
    return content;
}

- (float) heightForString:(NSString *)text andWidth:(float)width{
    NSInteger ch;
    UIFont *font = [UIFont systemFontOfSize:17];//11 一定要跟label的显示字体大小一致
    //设置字体
    CGSize size = CGSizeMake(width - 16, 2000.0f);//注：这个宽：300 是你要显示的宽度既固定的宽度，高度可以依照自己的需求而定
    //    if (SystemVersion_7x)//IOS 7.0 以上
    //    {
    NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil];
    
    if (text == nil || [text isEqual:[NSNull null]]) {
        ch = 0;
    }else{
        size =[text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:tdic context:nil].size;
        ch = size.height;
    }
    NSLog(@"高度：%ld",(long)ch);

    return size.height + 16.0;
}


//邀请好友
- (void)gotoInvitation{
    
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
